package com.itsitio.registeradmin.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itsitio.registeradmin.dao.BranchDao;
import com.itsitio.registeradmin.dao.base.SpringHibernateDao;
import com.itsitio.registeradmin.model.Branch;

@Repository
public class BranchDaoImpl extends SpringHibernateDao<Branch> implements BranchDao{

	@Autowired
	public BranchDaoImpl(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	@Override
	protected Class<Branch> getObjetoManejado() {
		return Branch.class;
	}

	public List<Branch> getBranchListByCompany(Integer companyId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(getObjetoManejado());
		criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
		criteria.add(Restrictions.eq("company.id", companyId));
		return  getHibernateTemplate().findByCriteria(criteria);
	}

}
